package com.clms.rents.service.impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clms.common.R;
import com.clms.rents.mapper.TabCarConfigMapper;
import com.clms.rents.pojo.entity.TbCarTypeConfigDetails;
import com.clms.rents.pojo.vo.CarConfigVo;
import com.clms.rents.service.CarConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: clms-third
 * @description: 汽车配置表的业务层
 * @author: 杨浩
 * @create: 2021-07-22 10:41
 **/
@Service
public class CarConfigServiceimp implements CarConfigService {

    @Resource
    private TabCarConfigMapper tabCarConfigMapper;

    @Override
    public R selectAll() {
        List<TbCarTypeConfigDetails> tbCarTypeConfigDetails = tabCarConfigMapper.selectList(null);
        return R.ok().put("allCarConfig",tbCarTypeConfigDetails);
    }

    @Override
    public R pageSelect(Integer currentPage, Integer pageSize, CarConfigVo carConfigVo) {
        Page<TbCarTypeConfigDetails> page=new Page<>(currentPage,pageSize);
        QueryWrapper<TbCarTypeConfigDetails> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(carConfigVo.getConfigname())){
            queryWrapper.like("configname",carConfigVo.getConfigname());
        }
        Page<TbCarTypeConfigDetails> page1=tabCarConfigMapper.selectPage(page,queryWrapper);
        return R.ok().put("total",page1.getTotal()).put("records",page1.getRecords());
    }

    @Override
    public R insert(TbCarTypeConfigDetails carTypeConfig) {
         int i=tabCarConfigMapper.insert(carTypeConfig);
         return R.ok();
    }

    @Override
    public R update(TbCarTypeConfigDetails carTypeConfig) {
      int i=tabCarConfigMapper.updateById(carTypeConfig);
      return R.ok();
    }

    @Override
    public R selectById(Integer id) {
        TbCarTypeConfigDetails tbCarTypeConfigDetails = tabCarConfigMapper.selectById(id);
        return R.ok().put("huixian",tbCarTypeConfigDetails);

    }

    @Override
    public R delete(Integer id) {
        int i=tabCarConfigMapper.deleteById(id);
        return R.ok();
    }
}
